package com.lr.api.controller.v1;

import com.lr.domain.entity.Employee;
import com.lr.service.EmployeeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/lab3")
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;

//    查询
    @GetMapping("/findEmploy")
    public ResponseEntity<?> findEmploy(){
        List<Employee> employee = employeeService.findEmployeeByCondition();
        return ResponseEntity.ok(employee);
    }

//    增加
    @PostMapping("/createEmploy")
    public ResponseEntity<?> createEmploy(@RequestBody  Employee employee){
        employeeService.createEmployee(employee);
        return ResponseEntity.ok(employee);
    }

//    删除
    @DeleteMapping("/deleteEmploy/{id}")
    public ResponseEntity<?> deleteEmploy(@PathVariable("id") Integer id){
        employeeService.deleteEmployee(id);
        return ResponseEntity.ok("删除成功");
    }

//  更新
    @PutMapping("/updateEmploy")
    public ResponseEntity<?> updateEmploy(@RequestBody  Employee employee){
        employeeService.updateEmployee(employee);
        return ResponseEntity.ok(employee);
    }

//    组合查询
    @GetMapping("/findEmployAndDepartment")
    public ResponseEntity<?> findEmployByCondition(){
        List<Employee> employee = employeeService.oneToOne();
        return ResponseEntity.ok(employee);
    }
}
